<?php
/**
 * Created by PhpStorm.
 * User: xmy2
 * Date: 18-8-12
 * Time: 上午12:03
 */

namespace vola;

class Log {

    /**
     * @var \vola\log\device\File
     */
    private $logs;

    private $level = ['emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info', 'debug'];

    public function __construct()
    {
        $type = 'File';
        if (Container::get('config')->get('log.type') != '') {
            $type = Container::get('config')->get('log.type');
        }
        $class = "\\vola\\log\\device\\" . $type;
        $this->logs = new $class();
    }

    public function recore( $name, $message = '',$level = 'info', array $context = []) {
        if (!in_array($level, $this->level)) {
            $level = 'info';
        }
        if (is_array($message)) {
            $message = var_export($message, true);
        }

        $this->logs->log($name, $message, $level, $context);
    }

    public function save() {
        $this->logs->save();
    }
}